import { Body, Controller, Get, Post, Query } from "@nestjs/common";
import { CreateLog, Roles } from "@/common/decorators";
import { Role } from "@/common/enum/role.enum";
import { SysMenu } from "@/database/entity/SysMenu";
import { CreateMenuDto } from "./dto/create-menu.dto";
import { UpdateMenuDto } from "./dto/update-menu.dto";
import { MenuService } from "./menu.service";

@Controller("sys/menu")
export class MenuController {
    constructor(private readonly menuService: MenuService) {}

    /** 创建系统菜单 */
    @CreateLog({ module: "系统菜单", type: "create", action: "创建系统菜单" }, SysMenu)
    @Roles(Role.SUPER_ADMIN)
    @Post("create")
    async create(@Body() menu: CreateMenuDto) {
        return this.menuService.create(menu);
    }

    /** 删除系统菜单 */
    @CreateLog({ module: "系统菜单", type: "delete", action: "删除系统菜单" }, SysMenu)
    @Roles(Role.SUPER_ADMIN)
    @Post("remove")
    async remove(@Body("id") id: string) {
        return this.menuService.remove(id);
    }

    /** 更新系统菜单 */
    @CreateLog({ module: "系统菜单", type: "update", action: "更新系统菜单" }, SysMenu)
    @Roles(Role.SUPER_ADMIN)
    @Post("update")
    async update(@Body() menu: UpdateMenuDto) {
        return this.menuService.update(menu);
    }

    /** 获取菜单树 */
    @Get("listTree")
    async listTree() {
        return this.menuService.listTree();
    }

    /** 根据id查询所有父节点 */
    @Get("listParentById")
    async listParentById(@Query("id") id: string) {
        return this.menuService.listParentById(id);
    }
}
